package com.my.hp_hr.dao;

import com.my.hp_hr.entity.Position;
import com.my.hp_hr.service.PositionService;
import com.my.hp_hr.util.BaseDAO;

import javax.servlet.http.HttpServlet;
import java.util.List;

public class PositionDao extends BaseDAO {

    public List<Position> ListPositon() throws Exception {
        String sql="select * from position;";
        Object[] obj={};
        List<Position> list = getList(sql, new Position(), obj);
        return list;
    }

    public void addPosition(Position position) throws Exception {
        String sql="insert into position values(null,?,?,?,?);";
        Object[] obj={position.getPosition_number(),position.getName(),position.getLevel(),position.getNotes()};
        addOrupdOrdel(sql,obj);
    }

    public Position getPositionById(String id) throws Exception {
        String sql="select * from position where id=?";
        Object[] obj={id};
        Position one = getOne(sql, new Position(), obj);
        return one;
    }

    public void updatePosition(Position position2) throws Exception {
        String sql="update position set id=?,position_number=?,name=?,level=?,notes=? where id=?;";
        Object[] obj={position2.getId(),position2.getPosition_number(),position2.getName(),position2.getLevel(),position2.getNotes(),position2.getId()};
        addOrupdOrdel(sql,obj);
    }

    public void delPosition(String id) throws Exception {
        String sql="delete from position where id=?;";
        Object[] obj={id};
        addOrupdOrdel(sql,obj);
    }

    public List<Position> getPageList(String pageNo) throws Exception {
        String sql="select * from position limit ?,?";
        int num=(Integer.parseInt(pageNo)-1)*5;
        Object[] obj ={num,5};
        List<Position> list = getList(sql, new Position(), obj);
        return list;
    }

    public int getPageCount() throws Exception {
        String sql="select count(1) from position";
        int count = getCount(sql, new Object[0]);
        return count;
    }
}
